package org.csmzxy.class2333;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


public class Example14 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("铅笔", 10);
        map.put("橡皮", 5);
        map.put("钢笔", 45);
        map.put("墨水", 15);
        Set<String> keys = map.keySet();
        System.out.println("1.用第一种方法遍历Map集合");
        for (String key : keys) {
            Integer value = map.get(key);
            System.out.println(key + "->" + value);
        }
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        System.out.println("2.用第二种方法遍历Map集合");
        for (Map.Entry<String, Integer> entry : entries) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + "->" + value);
        }
    }
}
